<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 1] 1.5 Notational Conventions</TITLE>
<META NAME="author" CONTENT="Mark Grand">
<META NAME="date" CONTENT="Thu Jul 31 13:05:20 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="java">
<META NAME="title" CONTENT="Java Language Reference">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java Language Reference" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch01_04.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 1<br>Introduction</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch02_01.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JLR2-CH-1-SECT-5">1.5 Notational Conventions</A></h2>

<P CLASS=para>
<A NAME="CH01.SYNTAX1"></A><A NAME="CH01.SYNTAX2"></A>One of the topics of this manual is the <I CLASS=emphasis>syntax</I>
of Java: the way that identifiers such as <tt CLASS=literal>foobar</tt>,
operators such as <tt CLASS=literal>+</tt>, and punctuation such as
<tt CLASS=literal>;</tt> can be put together to form a valid Java program.
This book also talks about
<I CLASS=emphasis>lexical structure</I> :
the sequences of characters that can be put together to form valid
numbers, identifiers, operators, and the like.

<P CLASS=para>
To describe syntax and lexical structure, many language reference
manuals use a notation called BNF. BNF notation is very helpful
to language implementors because it defines language constructs
in a way that can easily be turned into a working language parser.
Unfortunately, however, BNF can be difficult for human beings to
understand. This reference manual uses a different notation, called<A NAME="CH01.RAILROAD"></A>
a <I CLASS=emphasis>railroad diagram</I>, to describe syntax and
lexical structure. Railroad
diagrams are much easier for people to understand. A railroad diagram
provides a visual means of specifying the sequence of words, symbols,
and punctuation that can be used to write a syntactic
construct
or a lexical structure.

<P CLASS=para>
Here is a simple example:


<p>
<img align=middle src="./figs/jlr0101.gif" alt="[Graphic: Figure from the text]" width=396 height=11 border=0>

<P CLASS=para>
The idea is to follow the lines from left to right. The sequence
of words or symbols that you pass along the way is the sequence
of words or symbols that the railroad diagram specifies. The primary
rule when navigating railroad diagrams is that you can follow
lines from left to right only, unless there is an arrow pointing to
the left. In the above example, there are no arrows, so there
is only one way to navigate through the diagram. Therefore, the
above railroad diagram specifies exactly one sequence of words:
<tt CLASS=literal>ROW YOUR BOAT</tt>.

<P CLASS=para>
The next example provides you with a choice of sequences:


<p>
<img align=middle src="./figs/jlr0102.gif" alt="[Graphic: Figure from the text]" width=396 height=59 border=0>

<P CLASS=para>
You can navigate the above diagram with one of three sequences:

<P>
<UL CLASS=itemizedlist>
<li CLASS=listitem><tt CLASS=literal>ROW YOUR BOAT</tt>

<P>
<li CLASS=listitem><tt CLASS=literal>ROW YOUR CANOE</tt>

<P>
<li CLASS=listitem><tt CLASS=literal>ROW YOUR KAYAK</tt>

<P>
</UL>
<P CLASS=para>
The following example contains an arrow:


<p>
<img align=middle src="./figs/jlr0103.gif" alt="[Graphic: Figure from the text]" width=396 height=59 border=0>

<P CLASS=para>
In the above diagram, there is a left-pointing arrow on
the line under the word <tt CLASS=literal>ROW</tt>. That arrow means
that the line can only be traversed from right to left. The line
with the arrow provides a loop that allows the word <tt CLASS=literal>ROW</tt>
to be repeated one or more times, separated by commas. This allows
a sequence like: <tt CLASS=literal>ROW,ROW,ROW YOUR BOAT</tt>.

<P CLASS=para>
The railroad diagrams shown so far lack a feature that is
typically needed to make them useful: a name. A name allows
one railroad diagram to refer to another diagram. The following
railroad diagram defines a construct named <I CLASS=emphasis>color</I> :


<p>
<img align=middle src="./figs/jlr0104.gif" alt="[Graphic: Figure from the text]" width=406 height=70 border=0>

<P CLASS=para>
To further illustrate this point, let's look at two more railroad
diagrams. The first diagram defines a construct named <I CLASS=emphasis>size</I> :


<p>
<img align=middle src="./figs/jlr0105.gif" alt="[Graphic: Figure from the text]" width=403 height=45 border=0>

<P CLASS=para>
The second railroad diagram is similar to previous ones
except that now it allows an optional color or size to precede <tt CLASS=literal>BOAT</tt>,
<tt CLASS=literal>CANOE</tt>, or <tt CLASS=literal>KAYAK</tt>. The diagram
does this by referring to the names of the railroad diagrams that
define these things:


<p>
<img align=middle src="./figs/jlr0106.gif" alt="[Graphic: Figure from the text]" width=450 height=82 border=0>

<P CLASS=para>
In the diagrams in this book, the font for words such as <tt CLASS=literal>ROW</tt>
that are directly contained in railroad diagrams is different from
the font used for words like <I CLASS=emphasis>color</I> that are
names of railroad diagrams. The preceding railroad diagram allows
<I CLASS=emphasis>size</I> and <I CLASS=emphasis>color</I> to occur
more than once. The next diagram limits size and color to at most
one occurrence:


<p>
<img align=middle src="./figs/jlr0107.gif" alt="[Graphic: Figure from the text]" width=450 height=168 border=0>

<P CLASS=para>
The lines that refer to the <I CLASS=emphasis>size</I> and
<I CLASS=emphasis>color</I> diagrams both have semi-circles with
the number one under them. The semi-circles represent bridges that
collapse if crossed more than a certain number of times. The number
under the semi-circle is the number of times a bridge can be crossed.
Adding bridges that can be crossed only once creates a railroad
diagram that permits no more than one occurrence
of <I CLASS=emphasis>color</I>  and <I CLASS=emphasis>size</I>.

<P CLASS=para>
The other new feature introduced in the above railroad diagram
is a circle enclosing a number. These circles are connectors
used when a diagram does not fit across a page. The numbered
connector at the right end of one part of a railroad diagram attaches
to a connector with a matching number at the left end of another
part of the railroad diagram.

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch01_04.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch02_01.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>Running a Java Application</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>Lexical Analysis</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
